using System;
using System.Collections.Generic;
using System.Linq;
using Castle.DynamicProxy;
using Microsoft.Practices.ObjectBuilder2;

namespace UniAspect.Aspect.Emit
{
    [Obsolete]
    public class AspectInsertionPolicy : IAspectInsertionPolicy
    {
        private readonly ProxyGenerator _generator = new ProxyGenerator();
        private readonly IList<IAspect> _aspects = new List<IAspect>();

        public object CreateClassProxy(Type typeToCreate, IBuilderContext buildContext, object[] constructorArguments)
        {
            return _generator.CreateClassProxy(
                    typeToCreate, _aspects.ToArray(), constructorArguments);
        }

        public object CreateInterfaceProxy(object target, IBuilderContext buildContext)
        {
            var type = BuildKey.GetType(buildContext.BuildKey);
            return _generator.CreateInterfaceProxyWithTarget(
                    type, target, _aspects.ToArray());
        }

        public IList<IAspect> Aspects
        {
            get { return _aspects; }
        }

        public bool NoAspects
        {
            get { return _aspects.Count == 0; }
        }
    }
}